package org.jf.tool.fx.jftoolfx.settings.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import org.jf.tool.fx.jftoolfx.common.BaseController;
import org.jf.tool.fx.jftoolfx.util.JavaFXUtil;
import org.jf.tool.fx.jftoolfx.util.SettingsUtil;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 系统设置
 *
 * @author jifeng_zhang
 * @date 2025/8/18 下午8:04
 */
public class SettingsController extends BaseController {
    @FXML
    public ComboBox themeBox;

    public void save(ActionEvent actionEvent) {
        String theme = themeBox.getValue().toString();
        SettingsUtil.Settings settings = new SettingsUtil.Settings();
        settings.setTheme(theme);
        boolean result = SettingsUtil.saveSettings(settings);
        if (!result) {
            JavaFXUtil.msg(TOP_STAGE, "保存失败！");
            return;
        }
        JavaFXUtil.msg(TOP_STAGE, "保存成功,重启后生效！");
    }

    public void reset(ActionEvent actionEvent) {
    }

    @Override
    protected void init(URL url, ResourceBundle resourceBundle) {
        String theme = SettingsUtil.getTheme();
        themeBox.setValue(theme);
    }
}
